/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package hu.bme.j2ee.v37zen.beans.util;

import hu.bme.j2ee.v37zen.beans.FindUsersBean;
import hu.bme.j2ee.v37zen.beans.RegisterUserBean;
import hu.bme.j2ee.v37zen.entities.User;
import hu.bme.j2ee.v37zen.util.Role;
import java.util.List;
import javax.annotation.PostConstruct;
import javax.ejb.EJB;
import javax.ejb.Singleton;
import javax.ejb.Startup;

/**
 *
 * @author Kiss Dániel
 */
@Singleton
@Startup
public class StartupBean {
    
    @EJB
    FindUsersBean fub;
    @EJB
    RegisterUserBean rub;
    @EJB
    CleanupBean clb;
    
    @PostConstruct
    public void postConstruct(){
        
        System.out.println("[SD] Startup!");
        
        clb.removeAllUser();
        
        if(fub.isUserTableEmpty()){
            System.out.println("User table is empty!");
            
            rub.createUser("dani", "kissdani89@gmail.com", "password");
            
            //User user = new User("dani", "kissdani89@gmail.com", "password");
            //rub.registerUser(user);
            
            rub.createAdministrator("admin", "nass.diki@gmail.com", "password");
            
            //user = new User("admin", "nass.diki@gmail.com", "password", Role.SET_of_USDER_AND_ADMIN);
            //rub.registerUser(user);
        }      
        
        
        List<User> users = fub.findAllUser();
        for (User user : users) {
            System.out.println("[SD] " + user.toString());
        }
        
        System.out.println("[SD] Startedup!");
    }

    // Add business logic below. (Right-click in editor and choose
    // "Insert Code > Add Business Method")

}
